package com.wantong.jianpu.customviews;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.wantong.jianpu.R;

import me.goldze.mvvmhabit.utils.StringUtils;

/**
 * @author PACY
 * @date 2022/4/24
 * description:
 */
public class MineItemView extends LinearLayout {
    String title;
    String content;

    TextView titleTv;
    TextView contentTv;
    ImageView lable;

    public MineItemView(Context context) {
        super(context);
    }

    public MineItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        /**
         * 加载布局  获取自定义属性
         */
        LayoutInflater.from(context).inflate(R.layout.mine_select_view, this, true);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MineItemView);
        title = a.getString(R.styleable.MineItemView_mineItemTitle);
        content = a.getString(R.styleable.MineItemView_mineItemContent);
        a.recycle();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        contentTv = findViewById(R.id.content);
        titleTv = findViewById(R.id.title);
        lable = findViewById(R.id.lable);
        setTitleTv(title);
        if (StringUtils.isNotEmpty(content)) {
            setContent(content);
            lable.setVisibility(GONE);
        } else {
            lable.setVisibility(VISIBLE);
            contentTv.setVisibility(GONE);
        }
    }

    /**
     * 设置图标
     */
    public void setContent(String content) {
        contentTv.setVisibility(VISIBLE);
        lable.setVisibility(GONE);
        contentTv.setText(content);
    }

    /**
     * 设置标题
     *
     * @param title
     */
    public void setTitleTv(String title) {
        titleTv.setText(title);
    }
}
